#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;
void Print(sigset_t &pending)
{
    std::cout<<"curr process pending signal://信号集";
    for(int sig=31;sig>=1;sig--)
    {
        if(sigismember(&pending,sig))
        {
            cout<<"1";
        }
        else
        {
            cout<<"0";
        }
    }
    cout<<endl;
}
void handler(int sig)
{
    cout<<"catch signal:"<<sig<<endl;
    //不断获取当前进程的pending信号集并打印
    sigset_t pending;
    sigemptyset(&pending);
    while(true)
    {
        sleep(1);
        sigpending(&pending);
        Print(pending);
    }
}
int main()
{
    struct sigaction act ,oact;
    act.sa_handler=handler;
    act.sa_flags=0;
    sigemptyset(&act.sa_mask);//初始化信号集为空
    sigaddset(&act.sa_mask,3);//将3号信号添加到信号集中
    sigaction(2,&act,&oact);
    cout<<"send signal 2 to process:"<<getpid()<<endl;
    while(1)
    {
        sleep(1);
    }
    return 0;
}
